import 'package:baselib/utils/px_base_util.dart';
import 'package:baselib/utils/string_base_util.dart';
import 'package:baselib/widgets/inkwell_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/**
 * 一般底部弹出选择器
 */
class CommSelectWidget extends StatelessWidget {
  List<String> datas;
  int initIndex;
  Function onSelectedItemChanged;
  Function onConfirm;
  Function onCancel;

  CommSelectWidget({
    Key key,
    this.datas,
    this.initIndex,
    this.onSelectedItemChanged,
    this.onConfirm,
    this.onCancel,
  }) : super(key: key) {
    selectedIndex = (initIndex ?? 0);
  }

  int selectedIndex;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: PxBaseUtil().px_203,
      child: Column(
        children: [
          Row(
            children: [
              InkWellButton(
                  onPressed: () => (onCancel==null)?((){}):onCancel(),
                  child: Container(
                    height: PxBaseUtil().px_39,
                    alignment: Alignment.center,
                    padding: EdgeInsets.only(
                      left: PxBaseUtil().px_12,
                      right: PxBaseUtil().px_12,
                    ),
                    child: Text(
                      StringBaseUtil().Cancel,
                      style: TextStyle(
                        fontSize: PxBaseUtil().px_14,
                        color: Colors.white,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  )),
              Expanded(child: Text('')),
              InkWellButton(
                  onPressed: () => (onConfirm==null)?((){}):onConfirm(selectedIndex),
                  child: Container(
                    height: PxBaseUtil().px_39,
                    alignment: Alignment.center,
                    padding: EdgeInsets.only(
                      left: PxBaseUtil().px_12,
                      right: PxBaseUtil().px_12,
                    ),
                    child: Text(
                      StringBaseUtil().Done,
                      style: TextStyle(
                        fontSize: PxBaseUtil().px_14,
                        color: Colors.white,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  )),
            ],
          ),
          Stack(
            children: [
              Positioned(
                bottom: PxBaseUtil().px_55,
                child: Container(
                  height: PxBaseUtil().px_48,
                  width: PxBaseUtil().screenWidth,
                  decoration: const BoxDecoration(
                    gradient: LinearGradient(
                      colors: [Color(0xffBF47FF), Color(0xff7602FD)],
                    ),
                  ),
                ),
              ),
              Container(
                height: PxBaseUtil().px_164,
                padding: EdgeInsets.all(PxBaseUtil().px_8),
                child: CupertinoPicker(
                  squeeze: 1,
                  diameterRatio: 3,
                  backgroundColor: Colors.transparent,
                  itemExtent: PxBaseUtil().px_48,
                  scrollController:
                  FixedExtentScrollController(initialItem: initIndex),
                  onSelectedItemChanged: (int selecedTempIndex){
                    selectedIndex = selecedTempIndex;
                    (onSelectedItemChanged==null)?((){}):onSelectedItemChanged(selectedIndex);
                  },
                  children: (datas ?? [])
                      .map((e) => Container(
                    height: PxBaseUtil().px_48,
                    alignment: Alignment.center,
                    child: Text(
                      e,
                      style: TextStyle(
                        fontSize: PxBaseUtil().px_14,
                        color: Colors.white,
                      ),
                    ),
                  ))
                      .toList(),
                ),
              )
            ],
          )

        ],
      ),
    );
  }
}
